Skip to content

ref: make PR comment workflow generic #89460

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

jianyuan
Copy link
Contributor

@jianyuan jianyuan commented Apr 12, 2025

  1. Make PR comment workflow and Open PR comment workflow generic by moving GitHub-specific methods to GitHubIntegration and generic methods to CommitContextIntegration.
  2. Move tests accordingly.
  3. Make get_pullrequest_files an abstract method of CommitContextClient.
  4. Move language parsers to source_code_management.

@jianyuan jianyuan requested review from a team as code owners April 12, 2025 13:03
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Apr 12, 2025
@jianyuan jianyuan force-pushed the ref/make-pr_comment-workflow-generic branch 2 times, most recently from e026de5 to a9510b4 Compare April 12, 2025 13:22
@jianyuan jianyuan requested a review from a team as a code owner April 12, 2025 22:42
@jianyuan jianyuan force-pushed the ref/make-pr_comment-workflow-generic branch 2 times, most recently from 96dd30e to aab80f2 Compare April 13, 2025 20:30
Comment on lines +1026 to +1087
def run_pr_comment_workflow(integration_name: str, pullrequest_id: int, project_id: int) -> None:
cache_key = debounce_pr_comment_cache_key(pullrequest_id=pullrequest_id)

try:
pr = PullRequest.objects.get(id=pullrequest_id)
assert isinstance(pr, PullRequest)
except PullRequest.DoesNotExist:
cache.delete(cache_key)
logger.info(_pr_comment_log(integration_name=integration_name, suffix="pr_missing"))
return

try:
organization = Organization.objects.get_from_cache(id=pr.organization_id)
assert isinstance(organization, Organization)
except Organization.DoesNotExist:
cache.delete(cache_key)
logger.info(_pr_comment_log(integration_name=integration_name, suffix="org_missing"))
metrics.incr(
MERGED_PR_METRICS_BASE.format(integration=integration_name, key="error"),
tags={"type": "missing_org"},
)
return

try:
repo = Repository.objects.get(id=pr.repository_id)
assert isinstance(repo, Repository)
except Repository.DoesNotExist:
cache.delete(cache_key)
logger.info(
_pr_comment_log(integration_name=integration_name, suffix="repo_missing"),
extra={"organization_id": organization.id},
)
metrics.incr(
MERGED_PR_METRICS_BASE.format(integration=integration_name, key="error"),
tags={"type": "missing_repo"},
)
return

integration = integration_service.get_integration(
integration_id=repo.integration_id, status=ObjectStatus.ACTIVE
)
if not integration:
cache.delete(cache_key)
logger.info(
_pr_comment_log(integration_name=integration_name, suffix="integration_missing"),
extra={"organization_id": organization.id},
)
metrics.incr(
MERGED_PR_METRICS_BASE.format(integration=integration_name, key="error"),
tags={"type": "missing_integration"},
)
return

installation = integration.get_installation(organization_id=organization.id)
assert isinstance(installation, CommitContextIntegration)

installation.run_pr_comment_workflow(
organization=organization,
repo=repo,
pr=pr,
project_id=project_id,
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think it's okay to move this into the original task instead of moving it into a function and calling it anyway

@jianyuan jianyuan force-pushed the ref/make-pr_comment-workflow-generic branch from 50dfcf3 to 9681243 Compare April 14, 2025 23:26
@jianyuan jianyuan force-pushed the ref/make-pr_comment-workflow-generic branch from 9681243 to 636110d Compare April 15, 2025 20:52
@jianyuan jianyuan marked this pull request as draft April 20, 2025 21:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Scope: Backend Automatically applied to PRs that change backend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants